package com.framework.boc.statistics.service.impl;

import com.framework.boc.statistics.entity.TemplateField;
import com.framework.boc.statistics.mapper.TemplateFieldMapper;
import com.framework.boc.statistics.service.ITemplateFieldService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 统计模板字段表 服务实现类
 * </p>
 *
 * @author Leil
 * @since 2020-12-23
 */
@Service
public class TemplateFieldServiceImpl extends ServiceImpl<TemplateFieldMapper, TemplateField> implements ITemplateFieldService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 新增或更新模板字段
     * @param field         模板字段对象
     * @return              新增或更新结果
     * @throws Exception    异常
     */
    public boolean addOrUpdate(TemplateField field) throws Exception {
        if (field.getTemplateId() == 0) {
            logger.error("模板ID不能为0");
            throw new Exception("模板ID不能为0");
        }
        if (field.getId() == 0) {
            field.setId(null);
        }
        boolean bool = this.saveOrUpdate(field);
        return bool;
    }

}
